package spittr.data.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import spittr.Spitter;
import spittr.data.SpitterRepository;

@Repository
public class HibernateSpitterRepository implements SpitterRepository{

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public Spitter save(Spitter spitter) {
        Session session = sessionFactory.openSession();
        System.out.println(session.createNativeQuery("SELECT version()").getSingleResult());

        return (Spitter) sessionFactory.openSession().save(spitter);
    }

    @Override
    public Spitter findByUsername(String username) {
        return null;
    }


    public Spitter findBuID(Long id){
        return sessionFactory.openSession().get(Spitter.class,id);
    };

}
